package de.clapp.backend.server;

import java.io.IOException;
import java.net.Socket;

import de.clapp.backend.network.CipherTCPSocket;
import de.clapp.backend.network.ClientReply;
import de.clapp.backend.requests.ServerRequest;

public class CipherServerRunnable implements Runnable
{
    // private TCPSocket socket;
    private ClientReply reply;

    public CipherServerRunnable(Socket socket)
    {
        try
        {
            // this.socket = new TCPSocket(socket);
            this.reply = new ClientReply(new CipherTCPSocket(socket,CipherTCPSocket.Mode.Server));
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }

    @Override
    public void run()
    {
        try
        {
            while (true)
            {
                ServerRequest request = this.reply.getRequest();
                System.out.println("Request erhalten");
                this.reply.answer(request.execute());
            }
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            // e.printStackTrace();
            // System.out.println("Client disconnected");
        }
    }
}
